package com.chinasoft04.mall.mapper;

import com.chinasoft04.mall.dto.Attribute;
import com.chinasoft04.mall.dto.AttributeSql;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AttributeMapper {

    @Select("select * from sp_attribute where cat_id = #{id} and attr_sel = #{sel}")
    List<Attribute> select(@Param("id") Integer id, @Param("sel")String sel);

    @Select("select * from sp_attribute where attr_id = #{attr_id}")
    Attribute selectById(Integer attr_id);

    @Insert("insert into sp_attribute(attr_name, cat_id, attr_vals,attr_sel) values (#{attr_name},#{cat_id},#{attr_vals},#{attr_sel})")
    @Options(keyColumn = "attr_id", keyProperty = "attr_id",useGeneratedKeys = true)
    int insert(Attribute attribute);

    @Delete("delete from sp_attribute where attr_id = #{attr_id} and cat_id = #{id}")
    int deleteById(@Param("id") Integer id, @Param("attr_id") Integer attr_id);

    @UpdateProvider(value = AttributeSql.class, method = "getDynamicSql")
    @Options(keyColumn = "attr_id", keyProperty = "attr_id",useGeneratedKeys = true)
    int update(Attribute attribute);
}
